home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / hls.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  109 lines

  1. ; $Id: hls.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1983-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. Pro HLS, Litlo, Lithi, Satlo, Sathi, Hue, Loops, Colr
  7. ;+
  8. ; NAME:
  9. ;    HLS
  10. ;
  11. ; PURPOSE:
  12. ;    Make a color table based on the HLS (Hue, Lightness, Saturation) 
  13. ;    color system.
  14. ;
  15. ; CATEGORY:
  16. ;    Z4 - Image processing, color table manipulation
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    HLS, Litlo, Lithi, Satlo, Sathi, Hue, Loops [, Colr]
  20. ;
  21. ; INPUTS:
  22. ;    Litlo:    Starting lightness, from 0 to 100%.
  23. ;
  24. ;    Lithi:    Ending lightness, from 0 to 100%.
  25. ;
  26. ;    Satlo:    Starting saturation, from 0 to 100%.
  27. ;
  28. ;    Sathi:    Ending stauration, from 0 to 100%.
  29. ;
  30. ;    Hue:    Starting Hue, from 0 to 360 degrees.  Red = 0 degs,
  31. ;        green = 120, blue = 240.
  32. ;
  33. ;     Loops:    The number of loops through the color spiral.  This 
  34. ;        parameter does not have to be an integer.  A negative value
  35. ;        causes the loops to traverse the spiral in the opposite 
  36. ;        direction.
  37. ;
  38. ; OUTPUTS:
  39. ;    No required outputs.
  40. ;
  41. ; OPTIONAL OUTPUT PARAMETERS:
  42. ;    Colr:    A (256,3) integer array containing the R, G, and B values
  43. ;        that were loaded into the color tables.
  44. ;        Red = colr(*,0), green = colr(*,1), blue = colr(*,2).
  45. ;
  46. ; COMMON BLOCKS:
  47. ;    COLORS:    Contains the red, green, and blue vectors on exit.
  48. ;
  49. ; SIDE EFFECTS:
  50. ;    The color tables are loaded.
  51. ;
  52. ; RESTRICTIONS:
  53. ;    None.
  54. ;
  55. ; PROCEDURE:
  56. ;    Adapted from program on page 619, Fundamentals of Interactive
  57. ;    Computer Graphics, Foley and Van Dam.
  58. ;
  59. ;    Using the input parameters, a spiral through the double-
  60. ;    ended HLS cone is traced.  Points along the cone
  61. ;    are converted from HLS to RGB.
  62. ;
  63. ; MODIFICATION HISTORY:
  64. ;    Written, DMS, Jan, 1983.
  65. ;    Changed common block, dms, 4/1987.
  66. ;-
  67.     common colors,red,green,blue,cur_red,cur_green,cur_blue
  68.     on_error,2                      ;Return to caller if an error occurs
  69.     S = (sathi-satlo)/25600.*findgen(256)+satlo/100.
  70.     L = (Lithi-Litlo)/25600.*findgen(256)+litlo/100.
  71.     HG = Loops*360./256.*findgen(256)+ Hue
  72.     Hmin = Min(hg)/360.
  73.     IF HMIN LT 0. THEN HMIN = FIX(HMIN)-1 ELSE $
  74.         HMIN =FIX(HMIN)
  75.     HG = (HG - Hmin*360.) mod 360.    ;Make all positive
  76.     HR = (HG +120) mod 360.
  77.     HB = (HG +240) mod 360.
  78. ;
  79.     N2 = (L LE .5)*(L+L*S) + (L GT .5)*(L+S-L*S)
  80.     N1 = 2*L - N2
  81.     N21 = (N2-N1)/60.
  82.     COLR = FLTARR(256,3)
  83. ;
  84.     FOR I=0,255 DO BEGIN        ;What a mess.
  85.       IF S[I] EQ 0. THEN COLR[I,*]=L[I] ELSE BEGIN
  86.         IF HR[I] LT 60. THEN COLR[I,0]=N1[I]+N21[I]*HR[I] ELSE $
  87.         IF HR[I] LT 180. THEN COLR[I,0]=N2[I] ELSE $
  88.         IF HR[I] LT 240. THEN COLR[I,0]=N1[I]+N21[I]*(240.-HR[I]) ELSE $
  89.             COLR[I,0]=N1[I]
  90.         IF HG[I] LT 60. THEN COLR[I,1]=N1[I]+N21[I]*HG[I] ELSE $
  91.         IF HG[I] LT 180. THEN COLR[I,1]=N2[I] ELSE $
  92.         IF HG[I] LT 240. THEN COLR[I,1]=N1[I]+N21[I]*(240.-HG[I]) ELSE $
  93.             COLR[I,1]=N1[I]
  94.         IF HB[I] LT 60. THEN COLR[I,2]=N1[I]+N21[I]*HB[I] ELSE $
  95.         IF HB[I] LT 180. THEN COLR[I,2]=N2[I] ELSE $
  96.         IF HB[I] LT 240. THEN COLR[I,2]=N1[I]+N21[I]*(240.-HB[I]) ELSE $
  97.             COLR[I,2]=N1[I]
  98.         ENDELSE
  99.        ENDFOR
  100. ;
  101.     COLR = FIX(COLR*255.)<255        ;CVT TO 0, 255.
  102.     RED = COLR[*,0]                ;SAVE IN COMMON
  103.     GREEN = COLR[*,1]
  104.     BLUE = COLR[*,2]
  105.     TVLCT,RED,GREEN,BLUE            ;LOAD COLORS
  106.     cur_red = red & cur_green = green & cur_blue = blue
  107.     RETURN
  108. END
  109.